Home:ALL Converter>How do I check if an object is moving

How do I check if an object is moving

Ask Time:2020-02-24T00:54:49         Author:Slim_Bun

Json Formatter

I am trying to do something in unity, And I need to know if the camera is moving or not.

This is the script:

GameObject MainCamara = GameObject.FindGameObjectWithTag("MainCamera");
NewPosition = new Vector3(player.position.x, player.position.y, -10);
positionChanging(NewPosition);
if (MainCamara.GetComponent<Rigidbody2D>() == null)
{
        CameraMoving = true;
}
if (MainCamara.GetComponent<Rigidbody2D>().velocity.magnitude > 0.01f)
{
    CameraMoving = true;
}
CameraMoving = false;

I am not getting any errors, but it still doesn't work

Author:Slim_Bun,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364589/how-do-i-check-if-an-object-is-moving
merkithuseyin :

Consider using:\n\nCamera.main.velocity\n\n\nFrom Unity Documentation",
2020-02-23T17:17:29
yy